<!-- 注册 -->
<!DOCTYPE html>
<html lang="en">

<head>
    <title>用户注册</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link href="/css/sb-admin-2.min.css" rel="stylesheet">
    <script src="/js/axios.min.js"></script>
</head>

<body class="bg-gradient-primary">

    <div class="container">

        <div class="card o-hidden border-0 shadow-lg my-5">
            <div class="card-body p-0">
                <div class="row">
                    <div class="col-lg-5 d-none d-lg-block bg-register-image"></div>
                    <div class="col-lg-7">
                        <div class="p-5">
                            <div class="text-center">
                                <h1 class="h4 text-gray-900 mb-4">创建账号!</h1>
                            </div>
                            <form class="user">
                                <div class="form-group">
                                    <input type="text" class="form-control form-control-user" id="regist_phone"
                                        name="regist_account" placeholder="手机号">
                                </div>
                                <div class="form-group">
                                    <input type="text" class="form-control form-control-user" id="regist_name"
                                        name="regist_name" placeholder="注册用户名">
                                </div>
                                <div class="form-group">
                                    <input type="password" class="form-control form-control-user" id="regist_pwd1"
                                        name="regist_pwd" placeholder="密码">
                                </div>
                                <div class="form-group">
                                    <input type="password" class="form-control form-control-user" id="regist_pwd2"
                                        name="regist_pwd_con" placeholder="确认密码">
                                </div>
                                <button type="button" class="btn btn-primary btn-user btn-block"
                                    onclick="submitBtn()">注册</button>
                                <hr>
                            </form>
                            <hr>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

<script>
    // 验证手机号
    function phoneReg () {
        var phone = document.getElementById("regist_phone").value;
        var reg = /^[1][0-9]{10}$/;
        if (reg.test(phone) == false) {
            window.alert("请输入正确的手机号!");
            return false;
        } else {
            return true;
        }
    }
    // 验证密码
    function pwdReg () {
        var pwd = document.getElementById("regist_pwd1").value;
        var pwd2 = document.getElementById("regist_pwd2").value;
        var reg = /^[a-z|0-9|A-Z][a-z|0-9|A-Z]{7,11}$/;//要求数字或字母,长度8-12位
        if (reg.test(pwd) == false) {
            window.alert("密码要求数字和字母组合,长度8-12位!");
            return false;
        } else if (pwd != pwd2) {
            window.alert("两次密码不一致!");
            return false;
        } else {
            return true;
        }
    }
    // 提交按钮
    function submitBtn () {
        if (phoneReg() && pwdReg()) {
            axios({
                method: 'post',
                url: '/register',
                data: {
                    uphone: document.getElementById("regist_phone").value,
                    upass: document.getElementById("regist_pwd1").value,
                    uname: document.getElementById("regist_name").value,
                }
            }).then(function (result) {
                window.alert(result.data.msg);
                if (result.data.code == 0) {
                    setTimeout(function () {
                        window.opener = null;
                        window.open('', '_self');
                        window.close();
                    }, 500);
                }
            });
        }
    }
</script>

</html>